package com.huang825172.sbog;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Environment;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;

import com.baidubce.BceClientException;
import com.baidubce.BceServiceException;
import com.baidubce.auth.DefaultBceCredentials;
import com.baidubce.services.bos.BosClient;
import com.baidubce.services.bos.BosClientConfiguration;
import com.baidubce.services.bos.model.PutObjectResponse;
import com.huang825172.sbog.Util.TAGs;

import java.io.File;
import java.io.IOException;

import me.rosuh.filepicker.config.FilePickerManager;

public class BOSTest extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bostest);

        BosClientConfiguration config = new BosClientConfiguration();
        config.setCredentials(new DefaultBceCredentials("fc524b5ee26746c69dd2d4bd23aa8faf", "0c30e6e1d9cb4618a961f7e165b8ccd9"));
        config.setEndpoint("http://gz.bcebos.com");
        final BosClient client = new BosClient(config);

        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    File file = new File("/sdcard/DCIM/Screenshots/Screenshot_20190323-123931_WeChat.jpg");
                    PutObjectResponse putObjFromFile = client.putObject("sbog", file.getName(), file);
                    Log.d(TAGs.INFO, putObjFromFile.getETag());
                } catch (BceServiceException e) {
                    System.out.println("Error ErrorCode: " + e.getErrorCode());
                    System.out.println("Error RequestId: " + e.getRequestId());
                    System.out.println("Error StatusCode: " + e.getStatusCode());
                    System.out.println("Error Message: " + e.getMessage());
                    System.out.println("Error ErrorType: " + e.getErrorType());
                } catch (BceClientException e) {
                    System.out.println("Error Message: " + e.getMessage());
                    e.printStackTrace();
                }
            }
        }).start();
    }
}
